#ifndef __CMARK_DEFS_H__
#define __CMARK_DEFS_H__

/*
 * Useful type-related stuff
 */

#define null NULL

#define type_bits(t)   (sizeof(t) * CHAR_BIT)
#define type_signed(t) (! ((t)0 < (t)-1))
#define type_min(t)    ((t) (!type_signed(t) ? (t)0 : ((t)1 << (type_bits(t) - 1))))
#define type_max(t)    ((!type_signed(t) ? (t)-1 : (t) ~ (~(t)0 << (type_bits(t) - 1))))

#ifndef min
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif

#ifndef max
#define max(a, b) ((a) > (b) ? (a) : (b))
#endif

/*
 * Compiler compatibility macros
 */

#if !defined(__BEGIN_DECLS) || !defined(__END_DECLS)

#undef __BEGIN_DECLS
#undef __END_DECLS

#if defined(__cplusplus)
#define	__BEGIN_DECLS extern "C" {
#define	__END_DECLS   }
#else /* !__cplusplus */
#define	__BEGIN_DECLS
#define	__END_DECLS
#endif /* !__cplusplus */

#endif /* !__BEGIN_DECLS || !__END_DECLS */

/*
 * Syntax sugar
 */

#define loop while (true)

#endif /* !__CMARK_DEFS_H__ */
